<?php
/**
 * 鐩綍琛ㄦā鍨�
 * 
 */
class dirModel extends model 
{
	public function __construct(){
		parent::__construct('beauty_dir','dir_id');
	}
	
	public function getDirTree($user_id,$parnet_dir_id,$type=null){
		if($parnet_dir_id == '0') {
			$cond = array('parent_dir_id'=>$parnet_dir_id,'user_id = 0 OR user_id'=>$user_id);
		} else {
			$cond = array('parent_dir_id'=>$parnet_dir_id,'user_id'=>$user_id);
		} 
		
		$field = array('dir_id','parent_dir_id','dir_name');
		$result = $this->findAll($cond,$field);
		if(!$type) 
			echo $this->turnToJsonData($result);
		else 
			return $result;
		//var_dump($result);
		//echo '[{"text":"IntroToExt","id":"\/IntroToExt","cls":"folder"},{"text":"INCLUDE_ORDER.txt","id":"\/INCLUDE_ORDER.txt","leaf":true,"cls":"file"},{"text":"air","id":"\/air","cls":"folder"},{"text":"adapter","id":"\/adapter","cls":"folder"},{"text":"license.txt","id":"\/license.txt","leaf":true,"cls":"file"},{"text":"ext-core.js","id":"\/ext-core.js","leaf":true,"cls":"file"},{"text":"source","id":"\/source","cls":"folder"},{"text":"CHANGES.html","id":"\/CHANGES.html","leaf":true,"cls":"file"},{"text":"resources","id":"\/resources","cls":"folder"},{"text":"ext-core-debug.js","id":"\/ext-core-debug.js","leaf":true,"cls":"file"},{"text":"ext-all-debug.js","id":"\/ext-all-debug.js","leaf":true,"cls":"file"},{"text":"docs","id":"\/docs","cls":"folder"},{"text":"filetree.tar.gz","id":"\/filetree.tar.gz","leaf":true,"cls":"file"},{"text":"ext-all.js","id":"\/ext-all.js","leaf":true,"cls":"file"},{"text":"eXtplorer_2.0.0.zip","id":"\/eXtplorer_2.0.0.zip","leaf":true,"cls":"file"},{"text":"build","id":"\/build","cls":"folder"},{"text":"eXtplorer_2.0.0","id":"\/eXtplorer_2.0.0","cls":"folder"},{"text":"IntroToExt.zip","id":"\/IntroToExt.zip","leaf":true,"cls":"file"},{"text":"examples","id":"\/examples","cls":"folder"},{"text":"filetree","id":"\/filetree","cls":"folder"}]';
	}
	private function turnToJsonData($data) {
		if(!empty($data)) {
			foreach($data as $row) {
				$tmp[] = array('text'=>$row['dir_name'],'id'=>$row['dir_id'],'cls'=>'folder','draggable'=>true);
			}
		}
		return json_encode($tmp);
	}
	
}
?>